package gui;

import java.awt.EventQueue;

import javax.swing.JFrame;
import javax.swing.JPanel;
import javax.swing.JLabel;
import java.awt.Font;
import javax.swing.JTextField;
import java.awt.Color;
import javax.swing.JButton;
import java.awt.event.ActionListener;
import java.awt.event.ActionEvent;

public class ArchitectureFrame {

	private JFrame frame;
	private JTextField pipeline;
	private JTextField reservStation;
	private JTextField rob;
	private JTextField addN;
	private JTextField mulN;
	private JTextField divN;
	private JTextField addEx;
	private JTextField mulEx;
	private JTextField divEx;
	private JTextField insBuffer;

	/**
	 * Launch the application.
	 */
	public static void main(String[] args) {
		EventQueue.invokeLater(new Runnable() {
			public void run() {
				try {
					ArchitectureFrame window = new ArchitectureFrame();
					window.frame.setVisible(true);
				} catch (Exception e) {
					e.printStackTrace();
				}
			}
		});
	}

	/**
	 * Create the application.
	 */
	public ArchitectureFrame() {
		initialize();
	}

	/**
	 * Initialize the contents of the frame.
	 */
	private void initialize() {
		frame = new JFrame();
		frame.setBounds(100, 100, 827, 500);
		frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
		frame.getContentPane().setLayout(null);
		
		JPanel archiPanel = new JPanel();
		archiPanel.setBounds(10, 11, 791, 440);
		frame.getContentPane().add(archiPanel);
		archiPanel.setLayout(null);
		
		JLabel lblMicroArchitecture = new JLabel("Micro Architecture:");
		lblMicroArchitecture.setFont(new Font("OCR A Extended", Font.BOLD | Font.ITALIC, 16));
		lblMicroArchitecture.setBounds(10, 11, 224, 33);
		archiPanel.add(lblMicroArchitecture);
		
		JLabel lblPipelineWidth = new JLabel("Pipeline width: ");
		lblPipelineWidth.setBounds(50, 75, 96, 14);
		archiPanel.add(lblPipelineWidth);
		
		JLabel lblRes = new JLabel("Number of reservation stations:");
		lblRes.setBounds(50, 111, 184, 14);
		archiPanel.add(lblRes);
		
		JLabel lblRobEntries = new JLabel("ROB entries:");
		lblRobEntries.setBounds(50, 150, 96, 14);
		archiPanel.add(lblRobEntries);
		
		JLabel lblFunctionalUnits = new JLabel("Functional Units:");
		lblFunctionalUnits.setBounds(50, 210, 116, 14);
		archiPanel.add(lblFunctionalUnits);
		
		JLabel lblAddsubUnits = new JLabel("ADD/SUB units:");
		lblAddsubUnits.setBounds(120, 235, 102, 14);
		archiPanel.add(lblAddsubUnits);
		
		JLabel lblMulUnits = new JLabel("MUL units:");
		lblMulUnits.setBounds(120, 260, 73, 14);
		archiPanel.add(lblMulUnits);
		
		JLabel lblDivUnits = new JLabel("DIV units:");
		lblDivUnits.setBounds(120, 285, 73, 14);
		archiPanel.add(lblDivUnits);
		
		JLabel lblExecutionTimein = new JLabel("Execution time (in cycles):");
		lblExecutionTimein.setBounds(370, 235, 149, 14);
		archiPanel.add(lblExecutionTimein);
		
		JLabel lblExecutionTimein_1 = new JLabel("Execution time (in cycles):");
		lblExecutionTimein_1.setBounds(370, 260, 149, 14);
		archiPanel.add(lblExecutionTimein_1);
		
		JLabel lblExecutionTimein_2 = new JLabel("Execution time (in cycles):");
		lblExecutionTimein_2.setBounds(370, 285, 149, 14);
		archiPanel.add(lblExecutionTimein_2);
		
		pipeline = new JTextField();
		pipeline.setBounds(162, 72, 44, 20);
		archiPanel.add(pipeline);
		pipeline.setColumns(10);
		
		reservStation = new JTextField();
		reservStation.setBounds(254, 108, 44, 20);
		archiPanel.add(reservStation);
		reservStation.setColumns(10);
		
		rob = new JTextField();
		rob.setBounds(136, 147, 44, 20);
		archiPanel.add(rob);
		rob.setColumns(10);
		
		addN = new JTextField();
		addN.setBounds(224, 232, 44, 20);
		archiPanel.add(addN);
		addN.setColumns(10);
		
		mulN = new JTextField();
		mulN.setBounds(224, 257, 44, 20);
		archiPanel.add(mulN);
		mulN.setColumns(10);
		
		divN = new JTextField();
		divN.setBounds(224, 282, 44, 20);
		archiPanel.add(divN);
		divN.setColumns(10);
		
		addEx = new JTextField();
		addEx.setBounds(529, 232, 44, 20);
		archiPanel.add(addEx);
		addEx.setColumns(10);
		
		mulEx = new JTextField();
		mulEx.setBounds(529, 257, 44, 20);
		archiPanel.add(mulEx);
		mulEx.setColumns(10);
		
		divEx = new JTextField();
		divEx.setBounds(529, 282, 44, 20);
		archiPanel.add(divEx);
		divEx.setColumns(10);
		
		final JLabel pipeReq = new JLabel("required");
		pipeReq.setForeground(Color.RED);
		pipeReq.setVisible(false);
		pipeReq.setFont(new Font("Tahoma", Font.ITALIC, 11));
		pipeReq.setBounds(338, 75, 46, 14);
		archiPanel.add(pipeReq);
		
		final JLabel rsReq = new JLabel("required");
		rsReq.setForeground(Color.RED);
		rsReq.setVisible(false);
		rsReq.setFont(new Font("Tahoma", Font.ITALIC, 11));
		rsReq.setBounds(359, 111, 46, 14);
		archiPanel.add(rsReq);
		
		final JLabel robReq = new JLabel("required");
		robReq.setForeground(Color.RED);
		robReq.setVisible(false);
		robReq.setFont(new Font("Tahoma", Font.ITALIC, 11));
		robReq.setBounds(234, 150, 46, 14);
		archiPanel.add(robReq);
		
		final JLabel addReq = new JLabel("required");
		addReq.setForeground(Color.RED);
		addReq.setVisible(false);
		addReq.setFont(new Font("Tahoma", Font.ITALIC, 11));
		addReq.setBounds(643, 235, 46, 14);
		archiPanel.add(addReq);
		
		final JLabel mulReq = new JLabel("required");
		mulReq.setForeground(Color.RED);
		mulReq.setVisible(false);
		mulReq.setFont(new Font("Tahoma", Font.ITALIC, 11));
		mulReq.setBounds(643, 260, 46, 14);
		archiPanel.add(mulReq);
		
		final JLabel divReq = new JLabel("required");
		divReq.setForeground(Color.RED);
		divReq.setVisible(false);
		divReq.setFont(new Font("Tahoma", Font.ITALIC, 11));
		divReq.setBounds(643, 285, 46, 14);
		archiPanel.add(divReq);
		
		JButton btnNext = new JButton("Next ->");
		btnNext.addActionListener(new ActionListener() {
			public void actionPerformed(ActionEvent arg0) {
				boolean valid = true;
				if (pipeline.getText().equals("")) {
					pipeReq.setVisible(true);
					valid = false;
				} else {
					pipeReq.setVisible(false);
				}
				if (reservStation.getText().equals("")) {
					rsReq.setVisible(true);
					valid = false;
				} else {
					rsReq.setVisible(false);
				}
				if (rob.getText().equals("")) {
					robReq.setVisible(true);
					valid = false;
				} else {
					robReq.setVisible(false);
				}
				if (addN.getText().equals("") || addEx.getText().equals("")) {
					addReq.setVisible(true);
					valid = false;
				} else {
					addReq.setVisible(false);
				}
				if (mulN.getText().equals("") || mulEx.getText().equals("")) {
					mulReq.setVisible(true);
					valid = false;
				} else {
					mulReq.setVisible(false);
				}
				if (divN.getText().equals("") || divEx.getText().equals("")) {
					divReq.setVisible(true);
					valid = false;
				} else {
					divReq.setVisible(false);
				}
				if (valid) {
					// go to next
				}
				
			}
		});
		btnNext.setBounds(650, 400, 89, 23);
		archiPanel.add(btnNext);
		
		JButton button = new JButton("<- Back");
		button.addActionListener(new ActionListener() {
			public void actionPerformed(ActionEvent arg0) {
			}
		});
		button.setBounds(30, 400, 89, 23);
		archiPanel.add(button);
		
		JLabel lblInstructionBufferSize = new JLabel("Instruction buffer size:");
		lblInstructionBufferSize.setBounds(50, 175, 143, 14);
		archiPanel.add(lblInstructionBufferSize);
		
		insBuffer = new JTextField();
		insBuffer.setBounds(212, 175, 44, 20);
		archiPanel.add(insBuffer);
		insBuffer.setColumns(10);
		
		JLabel lblRequired = new JLabel("required");
		lblRequired.setFont(new Font("Tahoma", Font.ITALIC, 11));
		lblRequired.setForeground(Color.RED);
		lblRequired.setBounds(290, 175, 46, 14);
		archiPanel.add(lblRequired);
	}
}
